﻿using System.Web.Security;
using System;

namespace MvcCms.Service.Code.Membership
{
    public interface IFormsAuthentication
    {
        void SignIn(string userName, bool createPersistentCookie);
        void SignOut();
    }

    public class FormsAuthenticationService : IFormsAuthentication
    {
        #region Constructors
        public FormsAuthenticationService()
        {
        }
        #endregion

        public void SignIn(string userName, bool createPersistentCookie)
        {
            FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
            var user = System.Web.Security.Membership.GetUser(userName);
            user.LastLoginDate = DateTime.Now;
            System.Web.Security.Membership.UpdateUser(user);
        }

        public void SignOut()
        {
            FormsAuthentication.SignOut();
        }

    }
}